﻿using System;
using System.Threading.Tasks;
using TradeDataAPI.Core.Configuration;

namespace TradeDataAPI.Core.Common
{
    public class BusCarNumberHelper
    {


        /// <summary>
        /// 计算需要多少个车辆
        /// </summary>
        /// <param name="numerator">人数</param>
        /// <returns></returns>
        /// <exception cref="DivideByZeroException"></exception>
        public static int ComputationNeedCarNum(int numerator)
        {
            try
            {
                int denominator = 42;
                if (!string.IsNullOrWhiteSpace(AppSetting.GetSection("Bus")["CarLoadNumber"]))
                {
                    denominator = Convert.ToInt32(AppSetting.GetSection("Bus")["CarLoadNumber"]);
                }

                int quotient = numerator / denominator;
                int remainder = numerator % denominator;

                if (remainder != 0)
                {
                    quotient += 1;
                }

                return quotient;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
                throw;
            }

        }
    }
}
